//
// Created by Administrator on 2022/12/25.
//

#ifndef AVPLAYER_FACETRACKER_H
#define AVPLAYER_FACETRACKER_H

#include <android/native_window_jni.h>
#include <pthread.h>
#include "opencv2/opencv.hpp"
#include "opencv2/imgproc/types_c.h"
#include "mylog.h"

using namespace cv;

class CascadeDetectorAdapter: public DetectionBasedTracker::IDetector
{
public:
    CascadeDetectorAdapter(cv::Ptr<cv::CascadeClassifier> detector):
            IDetector(),
            Detector(detector)
    {
        LOGD("CascadeDetectorAdapter::Detect::Detect");
        CV_Assert(detector);
    }

    void detect(const cv::Mat &Image, std::vector<cv::Rect> &objects)
    {
        LOGD("CascadeDetectorAdapter::Detect: begin");
        LOGD("CascadeDetectorAdapter::Detect: scaleFactor=%.2f, minNeighbours=%d, minObjSize=(%dx%d), maxObjSize=(%dx%d)", scaleFactor, minNeighbours, minObjSize.width, minObjSize.height, maxObjSize.width, maxObjSize.height);
        Detector->detectMultiScale(Image, objects, scaleFactor, minNeighbours, 0, minObjSize, maxObjSize);
        LOGD("CascadeDetectorAdapter::Detect: end");
    }

    virtual ~CascadeDetectorAdapter()
    {
        LOGD("CascadeDetectorAdapter::Detect::~Detect");
    }

private:
    CascadeDetectorAdapter();
    cv::Ptr<cv::CascadeClassifier> Detector;
};
class FaceTracker {

public:
    ANativeWindow *window= nullptr;
    pthread_mutex_t  mutex;
    Ptr<DetectionBasedTracker> tracker;


public:
    FaceTracker(const char *model);

    ~FaceTracker();

    void setANativeWindow(ANativeWindow *window);

    void draw(const Mat& img);
};


#endif //AVPLAYER_FACETRACKER_H
